package cn.dogger.thread.demo;

import cn.dogger.thread.config.NamedThreadFactory;
import cn.dogger.thread.config.ThreadPool;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author dogger
 * 2022/11/14 14:37
 */
public class Main{


    /**
     * 线程池对象
     */
    static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 20,
                60L, TimeUnit.SECONDS,
                new SynchronousQueue<>(), new NamedThreadFactory("dogger"), new ThreadPoolExecutor.CallerRunsPolicy());


    public static void main(String[] args) {
        for (int i = 0; i < 15; i++) {
            //创建任务
            Runnable runnable = () -> {
                try {
                    Thread.sleep(20);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName());
            };
            //threadPoolExecutor.execute(runnable);
            ThreadPool.execute(runnable);
        }

    }

}
